//获取列表表头数据 取listInfo中的value 取fieldInfo中的name show
export function formatTableCol(data: any) {
  const { listInfo, fieldInfo } = data
  const result = Object.keys(fieldInfo).map((item) => {
    return {
      key: item,
      ...fieldInfo[item]
    }
  })
  //只显示Show=true的列数据
  const column = result.filter((item: any) => item.isShow == 'true')
  return { listInfo, col: column }
}

export function getColWidth(list: any, boxWidth: number) {
  const result = list.map((item: any) => {
    return {
      ...item,
      width: Math.floor((item.width / 100) * boxWidth)
    }
  })
  return result
}

export function setLastWidth(list: any, boxWidth: number) {
  //先把最后一个元素去掉再求和
  const len = list.length
  const arr = list.slice(0, len - 1)
  const sumWidth = arr.reduce((first: number, cur: any) => first + cur.width, 0)
  const lastWidth = boxWidth - sumWidth
  list[len - 1].width = lastWidth
}
